#coding=utf8
import time,datetime
import itchat
from binancetrade import binance

line='-'*25+'\n'
wxid='filehelper'

itchat.auto_login(hotReload=True)#启动微信提示组件


def jincha(symbol,interval,limit,short_cycle,long_cycle):#查找出金叉，用5个时间单位进行判断
    ba=binance()
    req=ba.get_Klines(symbol,interval,limit)
    #使用5分钟K线，参数都放大100倍
    ma_short=ba.get_MA(short_cycle,0,req,100)
    ma_long=ba.get_MA(long_cycle,0,req,100)
    #ma_99=ba.get_MA(99,0,100,req)
    ma_short_5=ba.get_MA(short_cycle,5,req,100)
    ma_long_5=ba.get_MA(long_cycle,5,req,100)
    #ma_99_5=ba.get_MA(99,5,100,req)
    is_true=False

    if ma_short>=ma_long and ma_short_5<ma_long_5:#ma7,ma25金叉
        is_true=True
        info='%s 成金叉形态\n'%symbol
        # info+='MA(7):%.08f\n'%ma_short
        # info+='MA(25):%.08f\n'%ma_long
        # info+='MA(7_5):%.08f\n'%ma_short_5
        # info+='MA(25_5):%.08f\n'%ma_long_5
        print(info)
        itchat.send(info,wxid)#发微信消息
    return is_true



def main():
    interval_dict={'1m':'1分钟','5m':'5分钟','15m':'15分钟'}

    interval='5m'#K线类型
    limit=500    #数据量，最大500
    short_cycle=7#短周期线
    long_cycle=25#长周期线

    ba=binance()
    while 1:
        info=line
        info+='【金叉筛选】\n'
        info+='K线类型：%s\n短周期线：MA(%d)\n长周期线：MA(%d)\n'%(interval_dict[interval],short_cycle,long_cycle)
        info+=line
        print(info)
        itchat.send(info, wxid)#发微信消息
        for sym in ba.get_symbol_list('BTC'):
            jincha(sym,interval,limit,short_cycle,long_cycle)

if __name__=='__main__':
    main()